//
//  QTLifeCircleNetworkingTool.m
//  QTLifeCircle
//
//  Created by 王琼 on 17/1/15.
//  Copyright © 2017年 徐腾. All rights reserved.
//

#import "QTLifeCircleNetworkingTool.h"

@implementation QTLifeCircleNetworkingTool

+(instancetype)sharedManager{
    
    static QTLifeCircleNetworkingTool *instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[self alloc]init];
        instance.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/json",@"text/javascript",@"text/html",@"text/plain", nil];
        instance.requestSerializer.timeoutInterval = 3.f;
    });
    return instance;
}




-(void)GETWithURLStr:(NSString *)URLStr parameter:(NSDictionary *)parameters compeletionHandle:(void (^)(id))compeletion{
    
    
    [self GET:URLStr parameters:parameters progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        compeletion(responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"error = %@",error);
    }];
}

-(void)POSTWithURLStr:(NSString *)URLStr parameter:(NSDictionary *)parameters compeletionHandle:(void (^)(id))compeletion{
    
    
    //需要json请求
    self.requestSerializer = [AFJSONRequestSerializer serializer];
    
    [self POST:URLStr parameters:parameters progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (compeletion) {
            compeletion(responseObject);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"error = %@",error);
    }];
    
    
}


@end
